Make sure we actually return the index of a real item. (get_nth_item)
authorSoeren Sandmann <sandmann@daimi.au.dk>
Thu, 30 Oct 2003 15:30:24 +0000 (15:30 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Thu, 30 Oct 2003 15:30:24 +0000 (15:30 +0000)
Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>

* gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
return the index of a real item.
(get_nth_item) assert that the returned items is not a
placeholder.  (#125826, Marco Pesenti Gritti).

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktoolbar.c

index dcabbba2e107f6c0faf731c68f65141a93e4a48f..cabdbe2a3afbf3f276651f8ff6f5c0a72e25114a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
+       return the index of a real item.
+       (get_nth_item) assert that the returned items is not a
+       placeholder.  (#125826, Marco Pesenti Gritti).
+       
 2003-10-29  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkcellrendererseptext.c
index dcabbba2e107f6c0faf731c68f65141a93e4a48f..cabdbe2a3afbf3f276651f8ff6f5c0a72e25114a 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
+       return the index of a real item.
+       (get_nth_item) assert that the returned items is not a
+       placeholder.  (#125826, Marco Pesenti Gritti).
+       
 2003-10-29  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkcellrendererseptext.c
index dcabbba2e107f6c0faf731c68f65141a93e4a48f..cabdbe2a3afbf3f276651f8ff6f5c0a72e25114a 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
+       return the index of a real item.
+       (get_nth_item) assert that the returned items is not a
+       placeholder.  (#125826, Marco Pesenti Gritti).
+       
 2003-10-29  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkcellrendererseptext.c
index dcabbba2e107f6c0faf731c68f65141a93e4a48f..cabdbe2a3afbf3f276651f8ff6f5c0a72e25114a 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
+       return the index of a real item.
+       (get_nth_item) assert that the returned items is not a
+       placeholder.  (#125826, Marco Pesenti Gritti).
+       
 2003-10-29  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkcellrendererseptext.c
index dcabbba2e107f6c0faf731c68f65141a93e4a48f..cabdbe2a3afbf3f276651f8ff6f5c0a72e25114a 100644 (file)
@@ -1,3 +1,10 @@
+Thu Oct 30 16:20:58 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
+
+       * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually
+       return the index of a real item.
+       (get_nth_item) assert that the returned items is not a
+       placeholder.  (#125826, Marco Pesenti Gritti).
+       
 2003-10-29  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/gtkcellrendererseptext.c
index 3536ed01183a0c9d43974b80a3c6045f081d5008..3de4327605b3c0a52e779f1b20652eee32af494f 100644 (file)
@@ -1797,15 +1797,18 @@ logical_to_physical (GtkToolbar *toolbar, gint logical)
   g_assert (logical >= 0);
   
   physical = 0;
-  for (list = priv->content; list && logical > 0; list = list->next)
+  for (list = priv->content; list; list = list->next)
     {
       ToolbarContent *content = list->data;
 
       if (!content->is_placeholder)
        logical--;
       physical++;
-    }
 
+      if (!content->is_placeholder && logical == 0)
+       break;
+    }
+  
   g_assert (logical == 0);
   return physical;
 }
@@ -2730,20 +2733,26 @@ gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
 {
   GtkToolbarPrivate *priv;
   ToolbarContent *content;
+  gint n_items;
   
   g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
 
   if (!gtk_toolbar_check_new_api (toolbar))
     return NULL;
+
+  n_items = gtk_toolbar_get_n_items (toolbar);
+
+  if (n < 0 || n >= n_items)
+    return NULL;
   
   priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
 
   content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
-  
-  if (content)
-    return content->item;
 
-  return NULL;
+  g_assert (content);
+  g_assert (!content->is_placeholder);
+
+  return content->item;
 }
 
 /**